package com.twu.biblioteca.ui;

import com.twu.biblioteca.ui.components.Menu;
import com.twu.biblioteca.ui.components.MenuItem;

import java.util.Iterator;
import java.util.List;

/**
 * Created by madhu on 27/4/14.
 */
public class LibraryView {

    private static LibraryView libraryView = null;
    Menu menu;

    private LibraryView(){
        menu = new Menu();
    }

    public static LibraryView getInstance() {
        if(libraryView == null)
            libraryView = new LibraryView();
        return libraryView;
    }

    public void displayWelcomeMessage(String welcomeMessage) {
        System.out.println(welcomeMessage);
    }

    public void displayErrorMessage(String invalidUserChoiceMessage) {
        System.out.println(invalidUserChoiceMessage);
    }

    public void createMenu() {

        menu.addMenuItem(new MenuItem("List Books"));
        menu.addMenuItem(new MenuItem("List Movies"));
        menu.addMenuItem(new MenuItem("Login"));
        menu.addMenuItem(new MenuItem("Checkout Book"));
        menu.addMenuItem(new MenuItem("Return Book"));
        menu.addMenuItem(new MenuItem("Checkout Movie"));
        menu.addMenuItem(new MenuItem("User Profile"));
        menu.addMenuItem(new MenuItem("Quit"));

    }

    public void displayMenu() {

        List<MenuItem> menuItems = menu.getAllMenuItems();
        Iterator iterator = menuItems.iterator();
        int menuItemNumber = 1;
        System.out.println("MAIN MENU : \n");
        while(iterator.hasNext()) {
            System.out.println(menuItemNumber + ". " + ((MenuItem) iterator.next()).getName());
            menuItemNumber++;
        }
        System.out.println("\nChoose an option from 1 to "+menuItems.size());

    }

    public Menu getMenu() {
        return menu;
    }

}
